package com.act.moudles.baseAct.controller;

import com.act.moudles.baseAct.entity.TaskAnoPris;
import com.act.moudles.baseAct.service.TaskAnoPrisService;
import com.act.utils.DataResult;
import com.act.utils.PageSearch;
import com.act.utils.validations.AddGroup;
import com.act.utils.validations.UpdateGroup;
import com.act.utils.validations.ValidResult;
import com.act.utils.validations.ValidationUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("baseAct/taskAnoPris")
@Api(tags = "流程节点方法/权限")
public class TaskAnoPrisController {

    @Resource
    private TaskAnoPrisService taskAnoPrisService;

    @PostMapping("pageTaskPris")
    @ApiOperation("分页查询节点方法")
    public DataResult pageTaskPris(@RequestBody PageSearch<TaskAnoPris> prisPageSearch){
        Page<TaskAnoPris> page = Page.of(prisPageSearch.getPageNum(),prisPageSearch.getPageSize());
        return DataResult.success("查询成功！",taskAnoPrisService.pagePris(page,prisPageSearch.getDomain()));
    }

    @PostMapping("addPriss")
    @ApiOperation("新增方法")
    public DataResult addPris(@RequestBody TaskAnoPris taskAnoPris){
        // 校验接口参数
        ValidResult validResult = ValidationUtils.validateGroup(taskAnoPris, AddGroup.class);
        if (validResult.isHasErrors()) {
            return DataResult.fail(validResult.getErrorMsg());
        }
        String addRes = taskAnoPrisService.addPrivis(taskAnoPris);
        if(StringUtils.isNotEmpty(addRes)){
            return DataResult.fail(addRes);
        }
        return DataResult.success("新增成功！");
    }


    @PostMapping("updPris")
    @ApiOperation("修改方法")
    public DataResult updPris(@RequestBody TaskAnoPris taskAnoPris){
        // 校验接口参数
        ValidResult validResult = ValidationUtils.validateGroup(taskAnoPris, UpdateGroup.class);
        if (validResult.isHasErrors()) {
            return DataResult.fail(validResult.getErrorMsg());
        }
        String addRes = taskAnoPrisService.updatePrivis(taskAnoPris);
        if(StringUtils.isNotEmpty(addRes)){
            return DataResult.fail(addRes);
        }
        return DataResult.success("新增成功！");
    }

    @GetMapping("remove")
    public DataResult remove(Long id){
        boolean delFlag = taskAnoPrisService.removeById(id);
        return DataResult.success(delFlag,delFlag?"删除成功":"删除失败");
    }


}
